<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="技能名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入技能名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="certName">
        <el-input
          v-model="queryParams.certName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="审核中" value="1" />
          <el-option label="报名成功" value="2" />
          <el-option label="审核未通过" value="3" />
          <el-option label="已退款" value="4" />
          <el-option label="退款待审核" value="5" />
          <el-option label="退款未通过" value="6" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hps:skillEnroll:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-success"
          size="mini"
          @click="handleCheck"
          v-hasPermi="['hps:enroll:checkapplybatch']"
        >报名通过</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-success"
          size="mini"
          @click="handleCheck2"
          v-hasPermi="['hps:enroll:checkoutbatch']"
        >取消通过</el-button>
      </el-col>


    </el-row>

    <el-table v-loading="loading" :data="enrollList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报名编号" align="center" prop="orderNo" />
      <el-table-column label="技能名称" align="center" prop="name" />
      <el-table-column label="姓名" align="center" prop="certName" >
        <template slot-scope="scope">
          <el-button type="text" @click="openAthletes(scope.row.id)">{{scope.row.certName}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" >
      <template slot-scope="scope">
        <div v-if="scope.row.sex=='1'">男</div>
        <div v-if="scope.row.sex=='2'">女</div>
      </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="证书领取方式" align="center" prop="receive" />
      <el-table-column label="报名时间" align="center" prop="createTime"/>
      <el-table-column label="实付金额" align="center" prop="totalAmount"/>
      <el-table-column label="状态" align="center" prop="statusName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-error"
            @click="handleCheckOut(scope.row)"
            v-hasPermi="['hps:enroll:checkapply']"
            v-if="scope.row.status==1"
          >审核不通过</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-error"
            @click="handleCheckOut2(scope.row)"
            v-hasPermi="['hps:enroll:checkout']"
            v-if="scope.row.status==5"
          >审核不通过</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <el-dialog :visible.sync="dialogFormVisible" @close="close">
      <template>
        <div style="font-size: 22px;font-weight:bold;margin-top: -30px">报名信息</div>
      </template>
      <div>
        <div class="top">
          <div class="size">报名编号：{{traiInfo.orderNo}}</div>
          <div class="size">技能名称：{{traiInfo.name}}</div>
        </div>

        <div class="top">
          <div class="size">
            个人免冠照：
            <el-image v-for="url in urls" :key="url" :src="url" style="width: 156px; height: 234px;margin-left: 20px"
                      :preview-src-list="urls" z-index="20000"></el-image></div>
        </div>

        <div class="top">
          <div class="size">姓名：{{traiInfo.certName}}</div> <div class="size">性别：<span v-if="traiInfo.sex==1">男</span><span v-if="traiInfo.sex==2">女</span></div>
        </div>

        <div class="top">
          <div class="size">身份证号：{{traiInfo.certNo}}</div> <div class="size">手机号：{{traiInfo.phone}}</div>
        </div>

        <div class="top">
          <div class="size">学历：{{traiInfo.education}}</div> <div class="size">工作年限：{{traiInfo.workingYears}}</div>
        </div>

        <div class="top">
          <div class="size">是否有接触确诊病例：{{traiInfo.contactDiagnosis}}</div> <div class="size">近15天是否到过高危地区：{{traiInfo.highRisk}}</div>
        </div>

        <div class="top">
          <div class="size">通讯地址：{{traiInfo.address}}</div>
        </div>

        <div class="top">
          <div class="size">技能水平说明：{{traiInfo.skillLevel}}</div>
        </div>

        <div class="top">
          <div class="size">身体情况调查：{{traiInfo.healthSurvey}}</div>
        </div>

        <div style="font-size: 22px;font-weight:bold;margin-top: 30px">费用明细</div>

        <div class="top">
          <div class="size">证书领取方式：{{traiInfo.receive}}</div> <div class="size">报名时间：{{traiInfo.createTime}}</div>
        </div>

        <div class="top">
          <div class="size">实付金额：{{traiInfo.totalAmount}}</div> <div class="size">报名费：{{traiInfo.price}}</div>
        </div>

        <div class="top">
          <div class="size">免冠照服务费：{{traiInfo.photoCost}}</div> <div class="size">快递费：{{traiInfo.expressFee}}</div>
        </div>

      </div>
    </el-dialog>


    <!-- 审核不通过，审核意见 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >

        <el-form-item label="报名审核意见" prop="applyAudit" v-if="check==1">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="报名审核意见"
            v-model="form.applyAudit">
          </el-input>
        </el-form-item>

        <el-form-item label="取消审核意见" prop="outAudit" v-if="check==2">
          <el-input
            type="textarea"
            :rows="4"
            placeholder="取消审核意见"
            v-model="form.outAudit">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="readLoad">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getEnroll, delEnroll, addEnroll, updateEnroll, exportEnroll,sitelist,
  checkApply,checkOut,checkApplyBatch,checkOutBatch,exportSkillEnroll,listEnroll } from "@/api/hps/enroll";
export default {
  name: "skillEnroll",
  data() {
    return {
      // 遮罩层
      loading: true,
      readLoad: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      //判断报名或退赛、1报名、2退赛
      check:0,
      // 报名信息表格数据
      enrollList: [],
      //运动员详情附件
      urls:[],
      baseUrl: process.env.VUE_APP_BASE_API,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dialogFormVisible: false,
      //报名详细信息
      traiInfo:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        certName: undefined,
        name: undefined,
        status: undefined,
        groupName:undefined,
        dataType:'1'

      },
      // 表单参数
      form: {
        id:undefined,
        applyAudit:undefined,
        outAudit:undefined,
        status:undefined
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报名信息列表 */
    getList() {
      this.loading = true;
      listEnroll(this.queryParams).then(response => {
        this.enrollList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //打开个人信息
    openAthletes(id){
      getEnroll(id).then(response => {
        this.traiInfo=response.data;
        //把附件地址转成数组
        var arry=[];
        if(response.data.pics==null){
          arry=[''];
        }else{
          arry =response.data.pics.split(',');
        }
        //清理数组最后一个空格
        var newArry=[];
        var baseUrl=this.baseUrl;
        arry.map(function(item){
          if(item!='' && item!=undefined)
          {
            newArry.push(item)
          }
        })
        this.urls=newArry;
        console.log(this.urls)
        this.dialogFormVisible=true;
      });

    },

    //关闭运动员信息
    close(){
      this.dialogFormVisible=false;
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id:undefined,
        applyAudit:undefined,
        outAudit:undefined,
        status:undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报名信息";
    },
    /** 报名审核不通过 */
    handleCheckOut(row) {
      this.reset();
      const id = row.id || this.ids
      getEnroll(id).then(response => {
      this.check=1;
      this.form.id = id;
      this.open = true;
      this.title = "审核意见";
      });
      this.check=0;
    },

    /** 退赛审核不通过 */
    handleCheckOut2(row) {
      this.reset();
      const id = row.id || this.ids
      getEnroll(id).then(response => {
        this.check=2;
        this.form.id = id;
        this.open = true;
        this.title = "审核意见";
      });
      this.check=0;
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            if(this.check==1){
              let query = ""
              if (this.ids.length > 0) {
                for (let i = 0; i < this.ids.length;i++) {
                  this.ids[i] = "ids=" + this.ids[i]
                }
                query = this.ids.join("&")
              } else {
                query = "ids=" + this.form.id;
              }
              if (this.form.applyAudit != undefined && this.form.applyAudit != "") {
                query = query + "&applyAudit=" + this.form.applyAudit;
              }
              this.syncData(query);
            }

            if(this.check==2){
              checkOut(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("操作成功");
                  this.open = false;
                  this.getList();
                }
              });
            }

          }
        }
      });
    },
    syncData(query){
      var that = this;
      this.readLoad = true;
      checkApply(query).then(response => {
        that.getList();
        that.readLoad = false;
        that.$alert(response.msg, "生成结果", { dangerouslyUseHTMLString: true,type: "success" });
        that.open = false;
      }).catch(function(res) {
        that.getList();
        that.readLoad = false;
        that.open = false;
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delEnroll(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },

    /** 报名审核按钮操作 */
    handleCheck(row) {
      const ids = row.id || this.ids;
      console.log(ids)
      if(ids==undefined || ids==null ||ids.length==0){
        this.$message.error('请勾选至少一个待审核报名');
      }else{
        this.$confirm('是否确认审核通过报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return checkApplyBatch(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("操作成功");
        }).catch(function() {});
      }

    },
    /** 退赛审核按钮操作 */
    handleCheck2(row) {
      const ids = row.id || this.ids;
      if(ids==undefined || ids==null ||ids.length==0){
        this.$message.error('请勾选至少一个待退赛报名');
      }else{
        this.$confirm('是否确认审核通过报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return checkOutBatch(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("操作成功");
        }).catch(function() {});
      }

    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报名信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSkillEnroll(queryParams);
        }).then(response => {
        console.log(response.msg);
        this.download(response.msg,"职鉴报名记录.xlsx");
        }).catch(function() {});
    }
  }
};
</script>

<style>
  .size{
    font-size: 18px;
    width: 50%;
  }
  .top{
    display: flex;
    margin-top: 30px;
  }
</style>
